package 程序员面试金典;

public class 单词距离 {

    public int findClosest(String[] words, String word1, String word2) {
        int start=-10000,end=10000;
        int res=Integer.MAX_VALUE;
        for (int i = 0; i < words.length; i++) {
              if (words[i].equals(word1))
                  start=i;
              if (words[i].equals(word2))
                  end=i;
              res=Math.min(res,Math.abs(end-start));
        }
        return res;
    }

}
